package com.example.domain.property;

import com.example.domain.Blog;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.ToString;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Data
@Entity  //声明此类是一个实体类
@Table(name = "t_comment")   //配置实体类和表的映射关系,name:配置数据库表的名称
public class Comment {
    @Id   //声明主键的配置
    @GeneratedValue(strategy = GenerationType.IDENTITY)  //主键生成策略,IDENTITY自增
    private Long id;

    private String nickname;  //匿名
    private String email;  //邮箱
    private String content;  //评论内容
    private String avatar;  //头像

    @JsonFormat(shape= JsonFormat.Shape.STRING,pattern="yyyy-MM-dd",timezone="GMT+8")
    private Date createTime;  //创建时间

    //评论回复
    @OneToMany(mappedBy = "parent")
    private List<Comment> replyList;  //子评论们
    @ManyToOne
    @JsonIgnoreProperties("replyList")
    @ToString.Exclude
    private Comment parent;  //父评论

    @ManyToOne
    @JsonIgnoreProperties("comments")
    @ToString.Exclude
    private Blog blog;
}
